//用户头像切换
function change(){
    document.querySelector('[type="file"]').click()
}
function show(that){
    var fileReader=new FileReader()
    var reg=/^imag/gi
    fileReader.readAsDataURL(that.files[0])
    var cal=reg.test(that.files[0].type)
    console.log(that.files[0].size)
    if((that.files[0].size/1024)<1024&&cal){
        fileReader.onload=function(e){
            console.log(e.target.result)
            document.querySelector('.userLeft>img').src=e.target.result
        }
    }else{
        alert("文件错误")
    }
}

// iframe高度自适应
function changeFrameHeight(iframeObj){ 
    setTimeout(function(){
        if(!iframeObj) return;
        iframeObj.height=(iframeObj.Document?iframeObj.Document.body.scrollHeight:iframeObj.contentDocument.body.offsetHeight); 
    },200) 
}



//用户退出
var userInfo1=[]
var persons=[]
window.onload=function(){
   
    if( localStorage['userInfo']){       
    userInfo1=JSON.parse(localStorage['userInfo'])
        document.querySelector('.userName>h1').innerHTML=userInfo1[userInfo1.length-1][0].name
    }
     if( localStorage['person']){
        persons=JSON.parse( localStorage['person'])
        document.querySelector('.userName>h1').innerHTML=persons[0].person
        localStorage.removeItem('person')
     }
    document.getElementById('tran').onclick=function(){
        if(document.querySelector('.userName>input').value){      
        userInfo1[userInfo1.length-1][0].name=document.querySelector('.userName>input').value
        document.querySelector('.userName>h1').innerHTML=userInfo1[userInfo1.length-1][0].name
        localStorage['userInfo']=JSON.stringify(userInfo1)
        document.querySelector('.userName>input').value=null
        }
      


    }
    document.getElementById('remove').onclick=function(){
   localStorage.removeItem('userInfo')
   document.querySelector('.userName>h1').innerHTML="userName"
   location.href="zhuce.html"  
    localStorage.removeItem('caidan')
    }

 
    // if(localStorage['caidan']){
    //     alert("创建了新菜谱")

    // }

    // $(function(){
        
    //     $.getJSON('../json/collectMenu.json',function(response){
    //        var  responses=JSON.parse(response)
    //        responses.push(cais[0])
    //        response=JSON.stringify(responses)
    //     })
    // })
   
    document.getElementById('leave').onclick=function(){
     
        document.querySelector('.userName>h1').innerHTML="userName"
        location.href="login.html" 
      

    }

    //鼠标点击导航栏修改样式
    $('#menu_list li a').click(function () {
        var f = this;
        $('#menu_list li a').each(function () {
            this.className = this == f ? 'a_2' : 'a_1'
        })
    })

}


